<template>
  <app-dialog v-model="show" width="800px" title="账号掉水监控" @open="handleOpen">
    <div class="title">
      填入的订单数代表需要监控掉水的订单间隔，填入的赔率差代表需要监控的掉水范围，根据不同的订单数和掉水范围，可定义账号的不同质量，质量分为优质、普通、较差，若系统监控到账号处于较差状态，请及时关注该账号。
    </div>
    <div class="content" v-if="formrow.good_bad_config">
      <div class="content_item">
        <div class="content_item_title">优质</div>
        <div class="item">
          <el-form
            :inline="true"
            :model="formrow.good_bad_config"
            class="demo-form-inline"
            label-position="right"
            label-width="88px"
          >
            <el-form-item label="订单数:">
              <el-input
                v-model="formrow.good_bad_config.good.order_count"
                placeholder="订单数"
                style="width: 120px; height: 32px"
              />
            </el-form-item>
            <el-form-item label="赔率差:">
              <app-range-input
                :data="formrow.good_bad_config.good"
                :name1="`min_odd`"
                :name2="`max_odd`"
                style="width: 120px; height: 32px"
              />
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div class="content_item" style="margin-top: 12px">
        <div class="content_item_title">普通</div>
        <div class="item">
          <el-form
            :inline="true"
            :model="formrow.good_bad_config"
            class="demo-form-inline"
            label-position="right"
            label-width="88px"
          >
            <el-form-item label="订单数:">
              <el-input
                v-model="formrow.good_bad_config.ordinary.order_count"
                placeholder="订单数"
                style="width: 120px; height: 32px"
              />
            </el-form-item>
            <el-form-item label="赔率差:">
              <app-range-input
                :data="formrow.good_bad_config.ordinary"
                :name1="`min_odd`"
                :name2="`max_odd`"
                style="width: 120px; height: 32px"
              />
            </el-form-item>
          </el-form>
        </div>
      </div>
      <div class="content_item" style="margin-top: 12px">
        <div class="content_item_title">较差</div>
        <div class="item">
          <el-form
            :inline="true"
            :model="formrow.good_bad_config"
            class="demo-form-inline"
            label-position="right"
            label-width="88px"
          >
            <el-form-item label="订单数:">
              <el-input
                v-model="formrow.good_bad_config.bad.order_count"
                placeholder="订单数"
                style="width: 120px; height: 32px"
              />
            </el-form-item>
            <el-form-item label="赔率差:">
              <app-range-input
                :data="formrow.good_bad_config.bad"
                :name1="`min_odd`"
                :name2="`max_odd`"
                style="width: 120px; height: 32px"
              />
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>

    <template #footer>
      <el-button @click="handleClose">取消</el-button>
      <el-button type="primary" @click="handleSubmit">确定</el-button>
    </template>
  </app-dialog>
</template>
<script setup>
import { ElMessage } from 'element-plus'
import { http } from '@/utils/http'

const show = defineModel({ type: Boolean })
const emits = defineEmits(['change'])
const props = defineProps({
  data: Object,
})

const formrow = ref({})

const handleOpen = () => {
  formrow.value = JSON.parse(JSON.stringify(props.data))
}

const handleClose = () => {
  show.value = false
}

const convertToInt = obj => {
  return Object.entries(obj).reduce((acc, [key, value]) => {
    if (typeof value === 'object' && value !== null) {
      // 如果是对象，递归调用
      acc[key] = convertToInt(value)
    } else {
      // 否则将值转换为整数
      acc[key] = parseFloat(value)
    }
    return acc
  }, {})
}

const handleSubmit = () => {
  let a = JSON.parse(JSON.stringify(formrow.value))
  let body = {
    status: a.status,
    id: a.id,
    login_rule_id: a.login_rule.id,
    group_id: a.group.id,
    source_id: a.source.id,
    money_code: a.money.money_code,
    proxy_ip_id: a.proxy_ip.id,
    user_name: a.user_name,
    pass_word: a.pass_word,
    percent: a.percent,
    remark: a.remark,
    bc_type: a.bc_type,
    amount: a.amount,
    place_league: a.place_league,
    place_pk_key_amount: a.place_pk_key_amount,
    no_place_pk_key: a.no_place_pk_key,
    no_place_pk_type: a.no_place_pk_type,
    place_order_stakes: a.place_order_stakes,
    login_status: a.login_status,
  }
  body.good_bad_config = convertToInt(a.good_bad_config)

  http.post('/member/member_update', body).then(res => {
    ElMessage.success('操作成功')
    handleClose()
    emits('change')
  })
}
</script>
<style lang="scss" scoped>
.title {
  font-size: 13px;
  margin-bottom: 40px;
  color: #999;
}

.content {
  display: flex;
  flex-direction: column;

  .content_item_title {
    font-size: 16px;
    font-weight: 600;
    color: #252a30;
    margin-bottom: 16px;
  }
}
</style>
